package com.cc.controller;

import com.cc.entity.User;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
@RestController
public class UserController {
    //get 单参数
    @GetMapping("getParam")
    public String getParam(String name) {
        System.out.println(name);
        return name;
    }
    //get请求多参数
    @GetMapping("/getParam")
    public String getParam(@RequestParam("userName") String name,Integer age,String address){
        System.out.println("普通参数传递 name ==>"+name);
        System.out.println("普通参数传递 age ==>"+age);
        System.out.println("普通参数传递 address ==>"+address);
        return name;
    }
    //post请求form表单数据
    @PostMapping("/postParam")
    public String postParam(@RequestParam("userName") String name,Integer age,String address){
        System.out.println("普通参数传递 name ==>"+name);
        System.out.println("普通参数传递 age ==>"+age);
        System.out.println("普通参数传递 address ==>"+address);
        return name;
    }
    //对象参数
    @GetMapping("getPojoParams")
    public String postPojoParam(User user){
        System.out.println("接收pojo参数 user===>"+user);
        System.out.println("接收pojo嵌套参数 user===>"+user.getRole());
        return "接收参数成功";
    }
    //接收数组请求参数
    @GetMapping("arraysParams")
    public String arraysParams(String[] hobbies){
        System.out.println("数组参数传递 hobbies ==>"+ Arrays.toString(hobbies));
        return "接收数组请求参数";
    }
    //接收集合参数 list加@RequestParam
    @GetMapping("listParams")
    public String listParams(@RequestParam List<String> hobbies){
        System.out.println("集合参数传递 hobbies ==>"+hobbies);
        return "接收集合请求参数";
    }
    //接收前端json数据
    @GetMapping("getJsonParams")
    public String jsonParams(@RequestBody User user){
        System.out.println("json数据传递===>"+user);
        System.out.println("json数据传递===>"+user.getRole());
        return "接收前端json参数";
    }
    //接收json参数
    @PostMapping("/postJsonParam")
    public String postJsonParam(@RequestBody List<User> users){
        System.out.println("json数据传递===>"+users);
        return "接收json参数";
    }
}